import store from "@/store"

import { getAll as getTags } from "@/api/zhongyi/yaocaitag";

export const useZhongyiStore = defineStore("zhongyi", () => {
    const tags = ref([])
    
    const yaocaitags = computed(()=> {
      return tags.value.filter(todo => todo.type == '1')
    })

    const fangjitags = computed(()=> {
      return tags.value.filter(todo => todo.type == '1')
    })

    function buildOption(options) {
      if(options) {
      for(let option of options) {
        if(option.child.length == 0) {
          // option.child = null
          delete option.child
        }
        else {
          buildOption(option.child )
        }
      }
    }
    }

  const getTags =  async () {
    const res = await getTags()
        
        tags.value = buildOption(res.result)
      
  }
  
    return { 
      tags, 
      yaocaitags,fangjitags
      getTags, 
    }
})


  /** 在 setup 外使用 */
export function useDictionaryStoreHook() {
  return useDictionaryStore(store)
}
